// Copyright (C) 2021 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-ecmascript-function-objects-construct-argumentslist-newtarget
description: >
  ReferenceError when returning from a derived class constructor without calling
  `super()` is thrown after the function body has been left, so an iterator
  return handler can still call `super()`.
---*/

function Test() {
    var iter = {
      [Symbol.iterator]() {
        return this;
      },
      next() {
        return {done: false};
      },
      return() {
        // Calls |super()|.
        this.f();

        return {done: true};
      },
    };

    class C extends class {} {
      constructor() {
        iter.f = () => super();

        for (var k of iter) {
          return;
        }
      }
    }

    var o = new C();
    assert.sameValue(typeof o, "object");
}

// preheat
const NUMBER_OF_PREHEAT = 1;
for (let i = 0; i < NUMBER_OF_PREHEAT; i++) {
    Test();
}

ArkTools.jitCompileAsync(Test);
assert.sameValue(ArkTools.waitJitCompileFinish(Test), true, '[JIT] JIT disabled.');

// test
const NUMBER_OF_TEST = 1; // or 2
for (let i = 0; i < NUMBER_OF_TEST; i++) {
    Test();
}
